package top.xana.acg.music.ui.view

import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import top.xana.acg.common.utils.oval
import top.xana.acg.common.utils.radius
import top.xana.acg.music.R
/**
 * Created by xana on 2022/3/25 0025
 * Describe: cv4096@qq.com
 */
class ToolbarView @JvmOverloads constructor(
    context: Context,
    val attrs: AttributeSet? = null,
    defStyleAttr: Int = 0,
    defStyleRes: Int = 0
) : FrameLayout(context, attrs, defStyleAttr, defStyleRes), View.OnClickListener {


    val view by lazy { LayoutInflater.from(context).inflate(R.layout.view_toolbar, this) }
    val btnBack = view.findViewById<ImageView>(R.id.btn_back)
    val btnExt0 = view.findViewById<ImageView>(R.id.btn_ext_0)
    val btnExt1 = view.findViewById<ImageView>(R.id.btn_ext_1)
    val tvTitle = view.findViewById<TextView>(R.id.tv_title)

    init {

        val array = context.obtainStyledAttributes(attrs, R.styleable.ToolbarView)
        val style = array.getColor(R.styleable.ToolbarView_style, Color.BLACK)
        val title = array.getString(R.styleable.ToolbarView_title)
        array.recycle()

        tvTitle.let{
            it.setText(title?:"null")
            it.setTextColor(style)
        }
        btnBack.let {
            it.setOnClickListener(this)
            it.isActivated = (style == Color.WHITE)
            it.oval()
        }
        btnExt0.let {
            it.setOnClickListener(this)
            it.oval()
        }
        btnExt1.let {
            setOnClickListener(this)
            it.oval()
        }

    }

    override fun onClick(p0: View) {
        when(p0){
            btnBack-> Log.e(TAG, "返回")
            btnExt0->Log.e(TAG, "拓展0")
            btnExt1->Log.e(TAG, "拓展1")
        }
    }

    companion object{
        const val TAG = "ToolbarView"
    }
}
